ListView Option

Greetings,

Does anyone knows how to return the selected item to its original row? I want create something like the current group selection when creating a user, where it all goes to the orginal location.

I tried the following:
 

DB createViews
DBE lstCurrAttr, lstDspAttr
DBE btnUp, btnDown
string arr[] = {}
string attrName
int Num
Skip adName = createString()
 
void getAttrList()
{
Module m = current 
AttrDef ad
Num = 0
for ad in m do
{
    attrName = ad.name
        put(adName, attrName, Num)
        Num++
}
for attrName in adName do
{
        insert(lstCurrAttr, noElems(lstCurrAttr), (string key adName), iconNone)
}
//delete(adName)
}
 
void insertDspList (DBE btnDown)
{
int i = get(lstCurrAttr)
string insAttr = get(lstCurrAttr)
insert(lstDspAttr, noElems(lstDspAttr), insAttr, iconNone)
 
        for i in lstCurrAttr do
        {
                delete(lstCurrAttr, i)
        }
}
 
 
void removeDspList (DBE btnUp)
{
int i = get(lstDspAttr)
string remAttr = get(lstDspAttr)
string s
 
        if(find(adName, remAttr, Num))
        {
                //print remAttr ":\t" Num"\n"
                insert(lstCurrAttr, Num, remAttr, iconNone)
        }
 
 
        for i in lstDspAttr do
        {
                delete(lstDspAttr, i)
        }
}
 
void saveView(DB createViews)
{
 
}
 
 
 
createViews = create("Create Views", styleCentered)
lstCurrAttr = listView(createViews, 0, 300, 8, arr)
btnDown = button(createViews, downArrow, insertDspList)
btnUp = button(createViews, upArrow, removeDspList)
lstDspAttr = listView(createViews, 0, 300, 8, arr)
 
btnDown->"right"->"unattached"
 
 
 
btnUp->"left"->"flush"->btnDown
btnUp->"top"->"aligned"->btnDown
btnUp->"right"->"unattached"
 
 
 
apply(createViews , "Create View", saveView)
 
realize(createViews)
 
getAttrList()
insertColumn(lstCurrAttr, 1, "Current Attributes", 275, iconNone)
insertColumn(lstDspAttr, 1, "Current Attributes", 275, iconNone)
 
 
show(createViews)

 


Thanks in advance.

 


SystemAdmin - Mon Dec 07 09:59:07 EST 2009

Re: ListView Option
Mathias Mamsch - Mon Dec 07 17:25:28 EST 2009

Hey Douglas,

Skip lists have this amazing property that they will return numeric keys sorted, when you loop over them with "for item in skip do" ... So i just turned around key and value in your skip list - it will take care of keeping the order of the items. And i introduced another skip list which will remember which items are selected and voila!

And don't forget to check for a null selection (get listview will return -1)

Regards, Mathias
 

DB createViews
DBE lstCurrAttr, lstDspAttr
DBE btnUp, btnDown
string arr[] = {}
string attrName
int Num
 
Skip adName = create()
Skip skSelected = createString()
 
Module m = current 
AttrDef ad
Num = 0
for ad in m do
{
    attrName = ad.name
        put(adName, Num, attrName)
        Num++
}
 
void fillLists()
{
 
        empty lstCurrAttr
        empty lstDspAttr
 
        for attrName in adName do
        {
                // the listview will sort the values for us, just insert them in 
                // one or the other skip list, depending on if they are selected
                if (!find (skSelected, attrName)) 
                        insert(lstCurrAttr, noElems(lstCurrAttr), attrName, iconNone)
                else
                        insert (lstDspAttr, noElems(lstDspAttr), attrName, iconNone)
        }
}
 
void insertDspList (DBE btnDown)
{
        int i = get(lstCurrAttr)
        if (i < 0) return
        string insAttr = get(lstCurrAttr)
        // add item to selected list
        put (skSelected, insAttr, 0) 
        fillLists() 
}
 
 
void removeDspList (DBE btnUp)
{
        int i = get(lstDspAttr)
        if (i < 0) return
        string remAttr = get(lstDspAttr)
        // remove item from the selected list
        delete (skSelected, remAttr)
        fillLists()
}
 
void saveView(DB createViews)
{
 
}
 
createViews = create("Create Views", styleCentered)
lstCurrAttr = listView(createViews, 0, 300, 8, arr)
btnDown = button(createViews, downArrow, insertDspList)
btnUp = button(createViews, upArrow, removeDspList)
lstDspAttr = listView(createViews, 0, 300, 8, arr)
 
btnDown->"right"->"unattached"
 
btnUp->"left"->"flush"->btnDown
btnUp->"top"->"aligned"->btnDown
btnUp->"right"->"unattached"
 
apply(createViews , "Create View", saveView)
 
realize(createViews)
 
fillLists()
insertColumn(lstCurrAttr, 1, "Current Attributes", 275, iconNone)
insertColumn(lstDspAttr, 1, "Current Attributes", 275, iconNone)
 
show(createViews)